#include "ShowLeds.h"
#include "ui_ShowLeds.h"

ShowLeds::ShowLeds(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::ShowLeds)
{
	ui->setupUi(this);

	ui->widget->setLedsCount(20,10);
	ui->widget->showScreenShots(true);

	leds = ui->widget->getLeds();

	timer.setInterval(1000);
	connect(&timer, SIGNAL(timeout()), SLOT(timeOut()));
	timer.start();

	capture = new DirectXCapture(this);
}

ShowLeds::~ShowLeds()
{
	delete ui;
}

void ShowLeds::timeOut()
{
	capture->Capture();
	for(int i=0;i<20;i++){
		capture->MakeScreenshot(i*192/2,0,(i+1)*192/2,100);
		leds.at(i)->setColor(capture->GetAverage());
	}
	for(int i=0;i<10;i++){
		capture->MakeScreenshot(1910,i*108,1920,(i+1)*108);
		leds.at(20+i)->setColor(capture->GetAverage());
	}
	for(int i=0;i<20;i++){
		capture->MakeScreenshot(i*192/2,980,(i+1)*192/2,1080);
		leds.at(30+i)->setColor(capture->GetAverage());
	}
	for(int i=0;i<10;i++){
		capture->MakeScreenshot(0,i*108,100,(i+1)*108);
		leds.at(50+i)->setColor(capture->GetAverage());
	}
	capture->Release();
	qDebug() << capture->GetTime();
	ui->widget->update1();
}
